package cn.niit.dynamic;

import cn.niit.proxy.IHouseRental;
import cn.niit.proxy.OwnerRental;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyInvocationHandler implements InvocationHandler {
    private IHouseRental target;

    public MyInvocationHandler(IHouseRental target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        return null;
    }
    public Object getProxy(){
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object o, Method method, Object[] args) throws Throwable {
                        System.out.println("getProxy开始代理"+method.getName());
                        System.out.println("getProxy参数"+args);
                        Object returnVal=method.invoke(target,args);
                        System.out.println(returnVal);
                        System.out.println("getProxy完成代理");
                        return returnVal;


                    }
                }
        );
    }
}
